/**
 * 锥形瓶
 */
Zhuixingping = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_ZHUI_BOTTLE);
	},
	init:function(){
		var hand = new Button(this, 10, TAG_RIGHT, "#hand_right.png", this.callback);
		hand.setPosition(cc.p(30,-5));
		hand.setScale(0.7);
		hand.setVisible(false);
		var part = new Button(this, 12, TAG_RIGHT_PART, "#hand_right_part.png", this.callback);
		part.setPosition(cc.p(30,-5));
		part.setScale(0.7);
		part.setVisible(false);
		
		var hand2 = new Button(this, 10, TAG_LEFT, "#hand_left.png", this.callback);
		hand2.setPosition(cc.p(-30,-5));
		hand2.setScale(0.7);
		hand2.setVisible(false);
		var part2 = new Button(this, 12, TAG_LEFT_PART, "#hand_left_part.png", this.callback);
		part2.setPosition(cc.p(-30,-5));
		part2.setScale(0.7);
		part2.setVisible(false);
		
		
		
		this.body= new Button(this, 11, TAG_ZHUIXINGPING, "#zhuixingping.png", this.callback);
		zhui1= new Button(this, 11, TAG_ZHUIXINGPING1, "#zhui_red.png", this.callback);
		zhui1.setOpacity(0);
		zhui2= new Button(this, 11, TAG_ZHUIXINGPING2, "#zhui_yellow.png", this.callback);
		zhui2.setOpacity(0);
		zhui3= new Button(this, 11, TAG_ZHUIXINGPING3, "#zhui_pink.png", this.callback);
		zhui3.setOpacity(0);
		zhui3.setPosition(cc.p(0,0));
		zhui4= new Button(this, 11, TAG_ZHUIXINGPING4, "#zhui_orange.png", this.callback);
		zhui4.setOpacity(0);
		zhui4.setPosition(cc.p(0,0));
		
		var line=new cc.Sprite("#cyl.png");
		line.setOpacity(0);
		line.setPosition(19, -42 );
		line.setRotation(-20);
		this.addChild(line, 12, TAG_ZHUI_LINE);

		var part = new cc.Sprite("#zhui_part.png");
		part.setOpacity(0);
		part.setPosition(27, 50);
		this.body.addChild(part, 12, TAG_ZHUI_PART);
		
		this.body.setCascadeOpacityEnabled(true);
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	loadHand:function(){
		var hand2=new cc.Sprite("#hand2.png");
		this.addChild(hand2,5);
		hand2.setScale(0.8);
		hand2.setPosition(cc.p(this.width+90,0));
		var seq=cc.sequence(cc.delayTime(1.5),cc.callFunc(function() {
			hand2.removeFromParent();
		}, this));
		hand2.runAction(seq);
	},
	lineUp:function(){
		var line=this.getChildByTag(TAG_ZHUI_LINE);
		line.setOpacity(255);
		var move=cc.moveTo(1.5,cc.p(-1,-30));
		var sca=cc.scaleTo(1.5, 3.4,1);
		var spa=cc.spawn(move,sca);
		var mov=cc.moveTo(1, cc.p(-1,-15));
		var sca1=cc.scaleTo(1, 3,1)
		var spa2=cc.spawn(mov,sca1);
		var rot1=cc.rotateTo(0.6,0 );
		var seq=cc.sequence(spa,spa2,cc.delayTime(0.5),rot1);
		line.runAction(seq);
	},

	stir:function(time){
		// 产生波纹
		var line2 = new cc.Sprite("#beaker/line.png");
		line2.setPosition(27,36);
		line2.setScale(0.7);
//		line2.setColor(color);
		this.body.addChild(line2);

		var light = new cc.Sprite("#beaker/light.png");
		light.setPosition(line2.width * 0.5, 0);
		light.setScale(0.8);
		line2.addChild(light);

		var point = new cc.Sprite("#beaker/point.png");
		point.setScaleY(0.7);
		point.setPosition(light.width * 0.5, -point.height * 0.5);
		light.addChild(point);
		
		var rot=cc.rotateTo(0.2, -20);
		var rot1=cc.rotateTo(0.4, 20);
		var rot2=cc.rotateTo(0.2, 0);
		var seq = cc.sequence(rot,rot1,rot2,rot,rot1,rot2);
		light.runAction(cc.repeatForever(seq));
		this.scheduleOnce(function(){
//			line.setVisible(true);
			line2.removeFromParent(true);
		}, time);
	},

	callback:function(p){
		var func=cc.callFunc(this.actionDone,this);
		var action=gg.flow.flow.action;
		var hand=this.getChildByTag(TAG_RIGHT);
		var part=this.getChildByTag(TAG_RIGHT_PART);
		switch(p.getTag()){
		case TAG_ZHUIXINGPING:
			if(action==ACTION_DO1){

			}
			break;
		case TAG_ZHUIXINGPING1:
			hand.setVisible(true);
			part.setVisible(true);
			var mov1=cc.moveTo(0.1,cc.p(555,163.6));
			var mov2=cc.moveTo(0.1,cc.p(541,153.6));
			var mov3=cc.moveTo(0.1,cc.p(555,143.6));
			var mov4=cc.moveTo(0.1,cc.p(561,153.6));
			var seq=cc.sequence(mov1,mov2,mov3,mov4);
			var move=cc.moveTo(0.6, cc.p(170,211));
			var seq1=cc.sequence(cc.repeat(seq,2),move,cc.callFunc(function() {
				var huo_hand=this.getParent().getChildByTag(TAG_DDG_DDG).getChildByTag(TAG_HUO_HAND);
				huo_hand.setVisible(true);
				var huo_hand_part=this.getParent().getChildByTag(TAG_DDG_DDG).getChildByTag(TAG_HUO_HAND_PART);
				huo_hand_part.setVisible(true);
			}, this),this.callNext);
			this.runAction(seq1);
			break;
		case TAG_ZHUIXINGPING2:
			hand.setVisible(true);
			part.setVisible(true);
			var mov1=cc.moveTo(0.1,cc.p(555,163.6));
			var mov2=cc.moveTo(0.1,cc.p(541,153.6));
			var mov3=cc.moveTo(0.1,cc.p(555,143.6));
			var mov4=cc.moveTo(0.1,cc.p(561,153.6));
			var seq=cc.sequence(mov1,mov2,mov3,mov4);
			var move=cc.moveTo(0.6, cc.p(170,211));
			var seq1=cc.sequence(cc.repeat(seq,2),move,cc.callFunc(function() {
				var huo_hand=this.getParent().getChildByTag(TAG_DDG_DDG).getChildByTag(TAG_HUO_HAND);
				huo_hand.setVisible(true);
				var huo_hand_part=this.getParent().getChildByTag(TAG_DDG_DDG).getChildByTag(TAG_HUO_HAND_PART);
				huo_hand_part.setVisible(true);
			}, this),this.callNext);
			this.runAction(seq1);
			break;
		case TAG_ZHUIXINGPING3:
				var move=cc.moveTo(0.6, cc.p(555, 153.6));
				var seq=cc.sequence(cc.callFunc(function() {
					var huo_hand=this.getParent().getChildByTag(TAG_DDG_DDG).getChildByTag(TAG_HUO_HAND);
					huo_hand.setVisible(false);
					var huo_hand_part=this.getParent().getChildByTag(TAG_DDG_DDG).getChildByTag(TAG_HUO_HAND_PART);
					huo_hand_part.setVisible(false);
				}, this),move,cc.callFunc(function() {
					hand.setVisible(false);
					part.setVisible(false);
				}, this),this.callNext);
				this.runAction(seq);
			break;
		case TAG_ZHUIXINGPING4:
			var move=cc.moveTo(0.6, cc.p(555, 153.6));
			var seq=cc.sequence(cc.callFunc(function() {
				var huo_hand=this.getParent().getChildByTag(TAG_DDG_DDG).getChildByTag(TAG_HUO_HAND);
				huo_hand.setVisible(false);
				var huo_hand_part=this.getParent().getChildByTag(TAG_DDG_DDG).getChildByTag(TAG_HUO_HAND_PART);
				huo_hand_part.setVisible(false);
			}, this),move,cc.callFunc(function() {
				hand.setVisible(false);
				part.setVisible(false);
			}, this),this.callNext);
			this.runAction(seq);
			break;
		}
	},
	actionDone:function(p){
		switch(p.getTag()){
		case TAG_ZHUIXINGPING:			
			gg.flow.next();				
			break;
		case TAG_ZHUIXINGPING1:			
			gg.flow.next();				
			break;
		case TAG_ZHUIXINGPING2:			
			gg.flow.next();				
			break;
		case TAG_ZHUIXINGPING3:			
			gg.flow.next();				
			break;
		case TAG_ZHUIXINGPING4:			
			gg.flow.next();				
			break;
			

		}
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
});